using System;
using BMCommon;
using Data;
using UnityEngine;

public class LevelSetRoot : SingletonMonoBehaviour<LevelSetRoot>
{
	private int DataSetTotal
	{
		get
		{
			int num = 0;
			for (int i = 0; i < this.LevelSets.Length; i++)
			{
				num += this.LevelSets[i].portion;
			}
			return num;
		}
	}

	public void SetDataset()
	{
		if (this.IsABTesting)
		{
			int uniqueIndex = BMTool.GetUniqueIndex(SingletonMonoBehaviour<LevelSetRoot>.Instance.DataSetTotal);
			int num = 0;
			for (int i = 0; i < this.LevelSets.Length; i++)
			{
				num += this.LevelSets[i].portion;
				if (uniqueIndex < num)
				{
					DataContainer<Data.Root>.SetPostfix(this.LevelSets[i].name);
					break;
				}
			}
		}
		else
		{
			DataContainer<Data.Root>.SetPostfix("MASTER");
		}
	}

	public void Toggle(Action onComplete = null)
	{
		int num = this.LevelSets.Length;
		for (int i = 0; i < num; i++)
		{
			if (DataContainer<Data.Root>.GetPostfix() == this.LevelSets[i].name)
			{
				int num2 = (i + 1) % num;
				string name = this.LevelSets[num2].name;
				DataContainer<Data.Root>.SetPostfix(name);
				DataContainer<Data.Root>.Reload();
				break;
			}
		}
		if (onComplete != null)
		{
			onComplete();
		}
	}

	public bool IsABTesting;

	[SerializeField]
	private LevelSetInfo[] LevelSets;
}
